$.ajax({
	type: "get",
	url: "json/shengfen.js",
	dataType: "json",
	success: function(res) {
		var shengfen;
		shengfen = res.shengfen;
		load(shengfen);
	}
});

function load(shengfen) {
	if(shengfen == "pengyou") {
		$(document).ready(function() {
			mask($(".json_mask"), $(".json_mask .mask_content"));
		})
	} else if(shengfen == "zhuren") {
		$(document).ready(function() {
			mask($(".json1_mask"), $(".json1_mask .mask_content"));
		})
	}
}
//客人数组选座
var guests = [
	{ id: "1", name: "王重阳", 'pic': "images/pic/1.jpg" },
	{ id: "2", name: "周伯通", pic: "images/pic/2.jpg" },
	{ id: "3", name: "欧阳峰", pic: "images/pic/3.jpg" },
	{ id: "4", name: "黄蓉", pic: "images/pic/4.jpg" },
	{ id: "5", name: "郭靖", pic: "images/pic/5.jpg" },
	{ id: "6", name: "黄药师", pic: "images/pic/6.jpg" },
	{ id: "7", name: "杨过", pic: "images/pic/7.jpg" },
	{ id: "8", name: "小龙女", pic: "images/pic/8.jpg" },
	{ id: "9", name: "令狐冲", pic: "images/pic/9.jpg" },
	{ id: "10", name: "独孤求败", pic: "images/pic/10.jpg" },
	{ id: "11", name: "西门吹雪", pic: "images/pic/11.jpg" },
	{ id: "12", name: "陆小凤", pic: "images/pic/12.jpg" },
	{ id: "13", name: "李白", pic: "images/pic/13.jpg" },
	{ id: "14", name: "杜甫", pic: "images/pic/14.jpg" },
	{ id: "15", name: "白居易", pic: "images/pic/15.jpg" },
	{ id: "16", name: "东方不败", pic: "images/pic/16.jpg" },
	{ id: "17", name: "李清照", pic: "images/pic/17.jpg" },
	{ id: "1", name: "王重阳", pic: "images/pic/1.jpg" },
	{ id: "2", name: "周伯通", pic: "images/pic/2.jpg" },
	{ id: "3", name: "欧阳峰", pic: "images/pic/3.jpg" },
	{ id: "4", name: "黄蓉", pic: "images/pic/4.jpg" },
	{ id: "5", name: "郭靖", pic: "images/pic/5.jpg" },
	{ id: "6", name: "黄药师", pic: "images/pic/6.jpg" },
	{ id: "7", name: "杨过", pic: "images/pic/7.jpg" },
	{ id: "8", name: "小龙女", pic: "images/pic/8.jpg" },
	{ id: "9", name: "令狐冲", pic: "images/pic/9.jpg" },
	{ id: "10", name: "独孤求败", pic: "images/pic/10.jpg" },
	{ id: "11", name: "西门吹雪", pic: "images/pic/11.jpg" },
	{ id: "12", name: "陆小凤", pic: "images/pic/12.jpg" },
	{ id: "13", name: "李白", pic: "images/pic/13.jpg" },
	{ id: "14", name: "杜甫", pic: "images/pic/14.jpg" },
	{ id: "15", name: "白居易", pic: "images/pic/15.jpg" },
	{ id: "16", name: "东方不败", pic: "images/pic/16.jpg" },
	{ id: "17", name: "李清照", pic: "images/pic/17.jpg" },
	{ id: "1", name: "王重阳", pic: "images/pic/1.jpg" },
	{ id: "2", name: "周伯通", pic: "images/pic/2.jpg" },
	{ id: "3", name: "欧阳峰", pic: "images/pic/3.jpg" },
	{ id: "4", name: "黄蓉", pic: "images/pic/4.jpg" },
	{ id: "5", name: "郭靖", pic: "images/pic/5.jpg" },
	{ id: "6", name: "黄药师", pic: "images/pic/6.jpg" },
	{ id: "7", name: "杨过", pic: "images/pic/7.jpg" },
	{ id: "8", name: "小龙女", pic: "images/pic/8.jpg" },
	{ id: "9", name: "令狐冲", pic: "images/pic/9.jpg" },
	{ id: "10", name: "独孤求败", pic: "images/pic/10.jpg" },
	{ id: "11", name: "西门吹雪", pic: "images/pic/11.jpg" },
	{ id: "12", name: "陆小凤", pic: "images/pic/12.jpg" },
	{ id: "13", name: "李白", pic: "images/pic/13.jpg" },
	{ id: "14", name: "杜甫", pic: "images/pic/14.jpg" },
	{ id: "15", name: "白居易", pic: "images/pic/15.jpg" },
	{ id: "16", name: "东方不败", pic: "images/pic/16.jpg" },
	{ id: "17", name: "李清照", pic: "images/pic/17.jpg" },
	{ id: "1", name: "王重阳", pic: "images/pic/1.jpg" },
	{ id: "2", name: "周伯通", pic: "images/pic/2.jpg" },
	{ id: "3", name: "欧阳峰", pic: "images/pic/3.jpg" },
	{ id: "4", name: "黄蓉", pic: "images/pic/4.jpg" },
	{ id: "5", name: "郭靖", pic: "images/pic/5.jpg" },
	{ id: "6", name: "黄药师", pic: "images/pic/6.jpg" },
	{ id: "7", name: "杨过", pic: "images/pic/7.jpg" },
	{ id: "8", name: "小龙女", pic: "images/pic/8.jpg" },
	{ id: "9", name: "令狐冲", pic: "images/pic/9.jpg" },
	{ id: "10", name: "独孤求败", pic: "images/pic/10.jpg" },
	{ id: "11", name: "西门吹雪", pic: "images/pic/11.jpg" },
	{ id: "12", name: "陆小凤", pic: "images/pic/12.jpg" },
	{ id: "13", name: "李白", pic: "images/pic/13.jpg" },
	{ id: "14", name: "杜甫", pic: "images/pic/14.jpg" },
	{ id: "15", name: "白居易", pic: "images/pic/15.jpg" },
	{ id: "16", name: "东方不败", pic: "images/pic/16.jpg" },
	{ id: "17", name: "李清照", pic: "images/pic/17.jpg" },
	{ id: "1", name: "王重阳", pic: "images/pic/1.jpg" },
	{ id: "2", name: "周伯通", pic: "images/pic/2.jpg" },
	{ id: "3", name: "欧阳峰", pic: "images/pic/3.jpg" },
	{ id: "4", name: "黄蓉", pic: "images/pic/4.jpg" },
	{ id: "5", name: "郭靖", pic: "images/pic/5.jpg" },
	{ id: "6", name: "黄药师", pic: "images/pic/6.jpg" },
	{ id: "7", name: "杨过", pic: "images/pic/7.jpg" },
	{ id: "8", name: "小龙女", pic: "images/pic/8.jpg" },
	{ id: "9", name: "令狐冲", pic: "images/pic/9.jpg" },
	{ id: "10", name: "独孤求败", pic: "images/pic/10.jpg" },
	{ id: "11", name: "西门吹雪", pic: "images/pic/11.jpg" },
	{ id: "12", name: "陆小凤", pic: "images/pic/12.jpg" },
	{ id: "13", name: "李白", pic: "images/pic/13.jpg" },
	{ id: "14", name: "杜甫", pic: "images/pic/14.jpg" },
	{ id: "15", name: "白居易", pic: "images/pic/15.jpg" },
	{ id: "16", name: "东方不败", pic: "images/pic/16.jpg" },
	//{ id: "17", name: "李清照", pic: "images/pic/17.jpg" }
];
var add_table = "<div class='morebito_table'><div class='table'><img src='images/table.png'/><div class='table_num'>第<span class='number'>1</span>席</div></div><div class='seat'><img src='images/vacancy.png' /></div><div class='seat'><img src='images/vacancy.png' /></div><div class='seat'><img src='images/vacancy.png' /></div><div class='seat'><img src='images/vacancy.png' /></div><div class='seat'><img src='images/vacancy.png' /></div><div class='seat'><img src='images/vacancy.png' /></div></div>";
var tbn = $(".number").length; //总桌数
var allseat = tbn * 6; //总的位置数
//动态获取数据添加桌子
(function() {
	if(guests.length > 36) {
		if(guests.length % 6 == 0) {
			var zuoshu = parseInt(guests.length / 6) - 6;
		} else {
			var zuoshu = parseInt(guests.length / 6) - 5;
		}
		for(var j = 0; j < zuoshu; j++) {
			$(".morebito_table:last-of-type").before(add_table);
			tbn++;
			tbn = $(".number").length;
			allseat = tbn * 6;
		}
	}
	$(".num_of_peaple").html(guests.length);
	$(".your_num").html(guests.length + 1);
	//席号
	$(".morebito_table .number").each(function(i) {
		$(this).html(i + 1);
	});
	//获取数据改变座位的头像
	for(var i = 0; i < guests.length; i++) {
		$(".seat").eq(i).children("img").attr("src", guests[i].pic);
	};
})();
//判断是否要添加桌子
(function() {
	$(".morebito").on("touchend", '.morebito_table:last-of-type', function() {
		console.log(tbn * 6)
		if(tbn * 6 == guests.length) {
			tbn++;
			$(".morebito_table:last-of-type").before(add_table);
			$(".morebito_table .number").each(function(i) {
				$(this).html(i + 1);
			});
		} else {
			mask($(".kongwei_mask"), $(".kongwei_mask .mask_content"));
		}
	})
	$(".kongwei_mask .delete").on("touchend", function() {
		$(".kongwei_mask").fadeOut(500);
	})
})();
//主宾点击桌子放大缩小居中动画
(function() {
	var guest_onoff = true;
	var mydate = new Date();
	var bdhonoff = true;
	$(".guest .table").on("touchend", function() {
		if(new Date() - mydate > 600) {
			mydate = new Date();
			if(guest_onoff == true) {
				$(".morebito").fadeOut(100, function() {
					$(".guest").css({ "-webkit-transform": "matrix(2.3,0,0,2.3,0,270)", 'transition': "all 500ms" }); //transform的matrix矩阵（scaleX rotateY rotateX scaleY translateX translateY）
				});
				$(".pew").css("display", "none");
				$(".jzjw").css("display", "block");
				guest_onoff = false;

			} else if(guest_onoff == false) {
				$(".guest").css({ "-webkit-transform": "matrix(1,0,0,1,0,0)", 'transition': "all 500ms" });
				$(".morebito").fadeIn(100);
				guest_onoff = true;
				$(".pew").css("display", "block");
				$(".jzjw").css("display", "none");
			}
		}
	})
})();
var guest_onoff = true;
//各客宾桌动画
(function() {
	var mydate = new Date();
	
	$(".morebito").on("touchend", ".morebito_table:not(:last) .table", function() {
		console.log(this)
		var $left = $(this).offset().left;
		var $top = $(this).offset().top;
		var $D_width = $(document).width();
		var $D_height = $(document).height();
		var $width = $(this).width();
		var $height = $(this).height();
		var move_x = $D_width / 2 - $left - $width / 2;
		var move_y =
			console.log($D_width, $D_height, $left, $top, $width, $height);
		if(new Date() - mydate > 600) {
			mydate = new Date();
			if(guest_onoff == true) {
				$(".center").css("overflow", "hidden");
				$(".guest").css({ "transform": "scale(0)", "transition": " all 500ms", "opacity": "0" });
				$(this).parent(".morebito_table").siblings().fadeTo(100, 0, function() {
					$(this).css({ scale: 0 });
				});
				console.log(this)
				$(this).parent(".morebito_table").transition({
					scale: 3,
					x: ($D_width / 2 - $left - $width / 2) / 3 + "px",
					y: ($D_height / 2 - $top - $height / 2) / 3 + "px",
					//					scale:3
				}, 500)
				$(".pew").css("display", "none");
				guest_onoff = false;
			} else if(guest_onoff == false) {
				$(".center").css("overflow", "overlay");
				$(".guest").css({ "-webkit-transform": "matrix(1,0,0,1,0,0)", 'transition': "all 500ms", "opacity": "1" });
				$(this).parent(".morebito_table").transition({
					scale: 1
				}, 200, function() {

					this.transition({
						x: "0px",
						y: "0px"
					}, 300, function() {

						this.siblings().fadeIn(100, function() {
							console.log(this)
							$(this).css({
								'scale': 1,
								"opacity": 1
							});
						})
					})
				})
				$(".pew").css("display", "block");
				$(".jzjw").css("display", "none");
				guest_onoff = true;
			}
		}
	})
})();
//判断是否可以坐下
(function() {
	$(".banquet_main").on("touchend", ".seat", function() {
		if(guest_onoff == false) {
			if($(this).children().attr("src") == "images/vacancy.png") {
				$(this).children().attr("src", "images/common/melon.jpg");
				guests.push({ pic: "images/common/melon.jpg" })
				mask($(".zhufu_mask"), $(".zhufu_mask .mask_content"));
				$(".jzjw").css("display", "block");
				$(".jzjw .zhuohao").html($(this).parent().find(".number").html());
				$(".jzjw .weihao").html($(this).index())
			} else {
				mask($(".youren_mask"), $(".youren_mask .mask_content"));
			}
		}
	})
	$(".youren_mask .delete").on("touchend", function() {
		$(".youren_mask").fadeOut(500);
	})
	$(".zhufu_mask .delete").on("touchend", function() {
		$(".zhufu_mask").fadeOut(500);
	})
})();